//
//  RetrieveViewController.m
//  PHMall
//
//  Created by admin on 2018/1/25.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "RetrieveViewController.h"

@interface RetrieveViewController ()<UITextFieldDelegate>{
    UITextField *name;
    UITextField *passWord;
}
@end

@implementation RetrieveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=Localized(@"找回密码");
    self.view.backgroundColor=[UIColor whiteColor];
    [self setUI];
    // Do any additional setup after loading the view.
}

-(void)setUI{
    UIBarButtonItem *leftBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarAction)];
    self.navigationItem.leftBarButtonItem=leftBar;
    
    UIImageView *logo=[[UIImageView alloc]init];
    [self.view addSubview:logo];
    
    logo.image=[UIImage imageNamed:@"logo"];
    ViewBorderRadius(logo, 10, 0, [UIColor whiteColor]);
    [logo mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset((218-RectStatus.size.height-44-64));
        make.centerX.equalTo(self.view);
        make.width.height.offset(70);
        make.height.equalTo(logo.mas_width);
    }];
    
    name=[[UITextField alloc]init];
    name.placeholder=Localized(@"用户名");
    name.autocapitalizationType = UITextAutocapitalizationTypeNone;
    name.keyboardType=UIKeyboardTypeDefault;
    name.font=[UIFont systemFontOfSize:18];
    [self.view addSubview:name];
    [name mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(30);
        make.right.equalTo(self.view.mas_right).with.offset(-60);
        make.top.equalTo(logo.mas_bottom).with.offset(20);
        make.height.offset(40);
    }];
    
    UIView *nameLine=[[UILabel alloc]init];
    [self.view addSubview:nameLine];
    nameLine.backgroundColor=[UIColor orangeColor];
    [nameLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(name.mas_bottom);
        make.right.equalTo(self.view.mas_right).with.offset(-20);
        make.left.equalTo(self.view).with.offset(20);
        make.height.offset(1);
    }];
    
    passWord=[[UITextField alloc]init];
    passWord.placeholder=Localized(@"绑定的邮箱");
    passWord.delegate=self;
    passWord.font=[UIFont systemFontOfSize:18];
//    passWord.secureTextEntry = YES;
    [self.view addSubview:passWord];
    passWord.keyboardType=UIKeyboardTypeASCIICapable;
    [passWord mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(30);
        make.right.equalTo(self.view.mas_right).with.offset(-60);
        make.top.equalTo(name.mas_bottom).with.offset(30);
        make.height.offset(40);
    }];
    
    UIView *passLine=[[UILabel alloc]init];
    [self.view addSubview:passLine];
    passLine.backgroundColor=[UIColor orangeColor];
    [passLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(passWord.mas_bottom);
        make.right.equalTo(self.view.mas_right).with.offset(-20);
        make.left.equalTo(self.view).with.offset(20);
        make.height.offset(1);
    }];
    
    UIButton *login=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:login];
    [login setBackgroundImage:[UIImage imageNamed:@"背景渐变条"] forState:UIControlStateNormal];
    [login setTitle:Localized(@"发送验证") forState:UIControlStateNormal];
    [login addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [login mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(passLine.mas_bottom).with.offset(50);
        make.height.offset(44);
        make.left.equalTo(self.view).with.offset(20);
        make.right.equalTo(self.view.mas_right).with.offset(-20);
    }];
}
-(void)loginAction{
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"findpass"];
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    [parametersDic setValue:name.text forKey:@"user"];
    [parametersDic setValue:passWord.text  forKey:@"email"];
    [parametersDic setValue:@"ios"  forKey:@"model"];
    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
//        [self.hud hideAnimated:YES];
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] isEqualToString:@"200"]) {
      
        }
        
    } andFailure:^{
//        [self.hud hideAnimated:YES];
        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
